var core = require('core');

var setuid = function(req, res, next){
    core.db.schema.User.update({}, {$unset: {uid: ""}}, {upsert: false, multi: true}, function(){
        core.db.schema.User.find({}).sort({subscribe_time: 1}).exec(function(err,rest){

            var x = 0;
            var y = rest.length;

            var d = setInterval(function(){
                if(x < y){
                    core.db.schema.User.update({openid: rest[x].openid}, {$set: {}}, {upsert: true, multi: true}, function(errs, status){
                        x += 1;
                        console.log(errs,'====', status);
                    });
                }else
                    {
                        clearInterval(d);
                        res.send('success');
                    }
            }, 50);

        });
    });

};

module.exports = setuid;
